import { Badge, Flex, Popconfirm, Space, TableColumnsType, Tag, Tooltip, Typography } from 'antd'
import { NavigateFunction } from 'react-router-dom'
import type { IPresetAttrTableData, ITableData, ReorderExpandDetailVO, ReorderExpandListVO } from './types'
import { DIS_STATUSBANDBTNTEXT, STATUSBAND, TaskStatusText, USERTYPETEXT } from '@/constant'
export const BadgeColorMap: { [k: number | string]: string } = {
  0: 'cyan',
  1: 'blue',
  2: 'volcano',
  3: 'gold',
  4: 'green',
  5: 'purple',
}
export const useExportColumns = ({
  onDownload,
}: {
  onDownload: (info: ITableData) => void
}): TableColumnsType<ITableData> => [
  {
    title: '任务ID',
    dataIndex: 'taskId',
    key: 'taskId',
    align: 'center',
    width: 200,
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '导出类型',
    dataIndex: 'bizTypeName',
    key: 'bizTypeName',
    align: 'center',
    width: 200,
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    key: 'createTime',
    align: 'center',
    width: 200,
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '任务状态',
    dataIndex: 'taskStatus',
    key: 'taskStatus',
    align: 'center',
    width: 200,
    render: (info, rows) => {
      return info ? (
        info == 2 ? (
          <Tooltip title={rows?.failReason}>
            <Badge color={BadgeColorMap[info]} text={TaskStatusText[info] || '-'} />
          </Tooltip>
        ) : (
          <Badge color={BadgeColorMap[info]} text={TaskStatusText[info] || '-'} />
        )
      ) : (
        '-'
      )
    },
  },
  {
    title: '操作',
    align: 'center',
    width: 200,
    render: (_, rows) => {
      return (
        <Space size={'large'}>
          {rows?.fileId ? <Typography.Link onClick={() => onDownload(rows)}>下载</Typography.Link> : '-'}
        </Space>
      )
    },
  },
]
export const useReceiptColumns = ({
  onDownload,
}: {
  onDownload: (info: ITableData) => void
}): TableColumnsType<ITableData> => [
  {
    title: '任务ID',
    dataIndex: 'taskId',
    key: 'taskId',
    align: 'center',
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '制单类型',
    dataIndex: 'bizTypeName',
    key: 'bizTypeName',
    align: 'center',
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '创建者',
    dataIndex: 'userName',
    key: 'userName',
    align: 'center',
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    key: 'createTime',
    width: 200,
    align: 'center',
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '任务状态',
    dataIndex: 'taskStatus',
    key: 'taskStatus',
    align: 'center',
    render: (info) => {
      return info ? <Badge color={BadgeColorMap[info]} text={TaskStatusText[info] || '-'} /> : '-'
    },
  },
  {
    title: '订单总数',
    dataIndex: 'total',
    key: 'total',
    align: 'center',
    render: (_, rows) => {
      return (rows.successNum || 0) + (rows.failNum || 0)
    },
  },
  {
    title: '成功订单',
    dataIndex: 'successNum',
    key: 'successNum',
    align: 'center',
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '失败订单',
    dataIndex: 'failNum',
    key: 'failNum',
    align: 'center',
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '操作',
    align: 'center',
    render: (_, rows) => {
      return (
        <Space size={'large'}>
          <Space size={'large'}>
            {rows?.fileId ? <Typography.Link onClick={() => onDownload(rows)}>下载</Typography.Link> : '-'}
          </Space>
        </Space>
      )
    },
  },
]
export const useReorderColumns = ({
  onView,
}: {
  onView: (info: ReorderExpandListVO) => void
}): TableColumnsType<ReorderExpandListVO> => [
  {
    title: '任务ID',
    dataIndex: 'taskId',
    key: 'taskId',
    align: 'center',
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '计算周',
    dataIndex: 'weekNum',
    key: 'weekNum',
    align: 'center',
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '大类',
    dataIndex: 'bigClassName',
    key: 'bigClassName',
    align: 'center',
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    key: 'createTime',
    width: 200,
    align: 'center',
    render: (info) => {
      return info || '-'
    },
  },

  {
    title: '创建人',
    dataIndex: 'createUserName',
    key: 'createUserName',
    align: 'center',
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '导入明细',
    dataIndex: 'successNum123',
    key: 'successNum123',
    align: 'center',
    render: (_, rows) => {
      return <Typography.Link onClick={() => onView(rows)}>查看</Typography.Link>
    },
  },
  {
    title: '任务状态',
    dataIndex: 'taskStatusName',
    key: 'taskStatusName',
    align: 'center',
    render: (info) => {
      return info ? (
        <Badge color={info == '失败' ? 'volcano' : info == '成功' ? 'green' : 'blue'} text={info || '-'} />
      ) : (
        '-'
      )
    },
  },
]
export const useViewColumns = (): TableColumnsType<ReorderExpandDetailVO> => [
  {
    title: '序号',
    dataIndex: 'taskId',
    key: 'taskId',
    align: 'center',
    width: 100,
    render: (_, __, index) => {
      return index + 1
    },
  },
  {
    title: '款式编码',
    dataIndex: 'spuCode',
    key: 'spuCode',
    align: 'center',
    width: 100,
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '商品名称',
    dataIndex: 'spuName',
    key: 'spuName',
    align: 'center',
    width: 150,
    ellipsis: {
      showTitle: false,
    },
    render: (info) => {
      return (
        <Tooltip placement="topLeft" title={info}>
          {info || '-'}
        </Tooltip>
      )
    },
  },
  {
    title: '颜色',
    dataIndex: 'colorName',
    key: 'colorName',
    align: 'center',
    width: 100,
    render: (info) => {
      return info || '-'
    },
  },

  {
    title: '尺码',
    dataIndex: 'sizeName',
    key: 'sizeName',
    align: 'center',
    width: 100,
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '商品条码',
    dataIndex: 'skuCode',
    key: 'skuCode',
    align: 'center',
    width: 100,
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '企划修正返单数量',
    dataIndex: 'amendReorderNum',
    key: 'amendReorderNum',
    align: 'center',
    width: 100,
    render: (info) => {
      return info >= 0 ? info : '-'
    },
  },
  {
    title: '扩渗透需求量',
    dataIndex: 'expandNum',
    key: 'expandNum',
    align: 'center',
    width: 100,
    render: (info) => {
      return info >= 0 ? info : '-'
    },
  },
  {
    title: '扩渗透门店数量',
    dataIndex: 'expandStoreNum',
    key: 'expandStoreNum',
    align: 'center',
    width: 100,
    render: (info) => {
      return info >= 0 ? info : '-'
    },
  },
]
